package com.Webserver.controller;

import com.Webserver.http.HttpRequest;
import com.Webserver.http.HttpResponse;
import qrcode.QRCodeUtil;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * 工具相关
 */
public class ToolsController {
    /**
     * 生成二维码
     */
    public void createQR(HttpRequest request, HttpResponse response){
        System.out.println("开始生成二维码...");
        String content = request.getParameter("content");
        System.out.println("二维码生成完毕!!!"+content);
        try {
            QRCodeUtil.encode(content,response.getOutputStream());
            response.setContentType("image/jpeg");
            System.out.println("生成完毕!!!");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//        String str = "http://doc.canglaoshi.org";
//        try {
//            FileOutputStream fos = new FileOutputStream("qr.jpg");
//            //(String,图片,流,压缩)
//            QRCodeUtil.encode(str,"./webapps/myweb/balabala.jpg",fos,true);
//            System.out.println("生成完毕!!!");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
}
